﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;
using weikebuluo.Model;
using weikebuluo.DAL;
using weikebuluo.Common;

namespace weikebuluo.web.admin.wechat
{
    public partial class imagesset : weikeweixin.web.admin.cs.adminbase
    {
        w_images_dal imagesdal = new w_images_dal();
        protected w_images_model imagesmodel = new w_images_model();

        protected void Page_Load(object sender, EventArgs e)
        {

            DataTable dtimages = imagesdal.GetList("user_id=" + user_id).Tables[0];
            if (dtimages.Rows.Count > 0)
            {
                imagesmodel = imagesdal.GetModel(int.Parse(dtimages.Rows[0]["images_id"].ToString()));
            }

            switch (Request.Form["action"]) {
                case "bind":
                    bind();
                    break;
            }
        }

        private void bind() {
            DataTable dtimages = imagesdal.GetList("user_id=" + user_id).Tables[0];
            if (dtimages.Rows.Count > 0)
            {
                imagesmodel = imagesdal.GetModel(int.Parse(dtimages.Rows[0]["images_id"].ToString()));
            }
            imagesmodel.images_tishi = Request.Form["images_tishi"];
            imagesmodel.images_tishi2 = Request.Form["images_tishi2"];
            imagesmodel.images_num = int.Parse(Request.Form["images_num"].Trim().ToString());
            imagesmodel.user_id = int.Parse(user_id);
            imagesmodel.images_set = int.Parse(Request.Form["is_show"].ToString());
            if (dtimages.Rows.Count > 0)
            {
                imagesdal.Update(imagesmodel);
                Response.Write("{\"errno\":\"0\",\"tip\":\"设置成功！\",\"url\":\"imagesset.aspx\",\"error\":\"\"}");
            }
            else {
                imagesdal.Add(imagesmodel);
                Response.Write("{\"errno\":\"0\",\"tip\":\"设置成功！\",\"url\":\"imagesset.aspx\",\"error\":\"\"}");
            }
            Response.End();
        }

    }
}